﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:System.Windows.Controls.WpfPropertyGrid"
  xmlns:design="clr-namespace:System.Windows.Controls.WpfPropertyGrid.Design"
  xmlns:controls="clr-namespace:System.Windows.Controls.WpfPropertyGrid.Controls">

  <local:NamedColorList x:Key="NamedColorList"/>
  <local:NullValueConverter x:Key="NullValueConverter"/>
  <local:EnumValueConverter x:Key="enumValueConverter"/>
  <local:MultiBooleanToVisibilityConverter x:Key="multiBooleanToVisibilityConverter"/>
  <local:ExpanderHeaderWidthConverter x:Key="expanderHeaderWidthConverter"/>

  <DataTemplate x:Key="{x:Static local:EditorKeys.ComplexPropertyEditorKey}">
    <Expander>
      <Expander.Header>
        <TextBox Text="{Binding Value, Mode=OneWay}" IsEnabled="False"
                 Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Mode=OneWay, Path=ActualWidth, Converter={StaticResource expanderHeaderWidthConverter}, ConverterParameter=-29}"/>
      </Expander.Header>
      <design:PropertyItemsLayout Grid.IsSharedSizeScope="True" ItemsSource="{Binding SubProperties}"/>
    </Expander>
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.DefaultCategoryEditorKey}">
    <design:PropertyItemsLayout ItemsSource="{Binding Properties}"/>
  </DataTemplate>

  <!--Note that commit on typing cannot work together with the roolback since every keystroke is committed and the roolback value is lost-->
  <DataTemplate x:Key="{x:Static local:EditorKeys.DefaultEditorKey}">
    <TextBox
			x:Name="PART_editor"
			Text="{Binding Value, Mode=TwoWay}"
			IsReadOnly="{Binding IsReadOnly}"
			local:TextBoxExtender.CommitOnEnter="true"
			local:TextBoxExtender.RollbackOnEscape="true"
			local:TextBoxExtender.CommitOnTyping="false"
			/>
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.EnumEditorKey}">
    <controls:EnumDropdown
      x:Name="PART_editor"
      Style="{DynamicResource {x:Type ComboBox}}"
      PropertyValue="{Binding}"
      IsEnabled="{Binding IsEditable}">
      <ComboBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding Path=., Converter={StaticResource enumValueConverter}}" />
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </controls:EnumDropdown>
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.BooleanEditorKey}">
    <CheckBox x:Name="PART_editor" IsChecked="{Binding Value}" IsEnabled="{Binding IsEditable}" />
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.FontFamilyEditorKey}">
    <ComboBox
      x:Name="PART_editor"
      SelectedValue="{Binding Value}"
      ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}"
      IsEnabled="{Binding IsEditable}">
      <ComboBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </ComboBox>
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.NamedColorEditorKey}" DataType="{x:Type local:NamedColor}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Rectangle Fill="{Binding Brush}" Grid.Column="0" Width="100" Height="20" Margin="2" HorizontalAlignment="Center"/>
      <TextBlock x:Name="PART_editor" Margin="5,2,2,2" Text="{Binding Name}" Grid.Column="1" HorizontalAlignment="Center"/>
    </Grid>
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.BrushEditorKey}">
    <ComboBox
      x:Name="PART_editor"
      Text="{Binding Path=StringValue, Mode=TwoWay, Converter={StaticResource NullValueConverter}}"
      ItemsSource="{Binding Source={StaticResource NamedColorList}}"
      ItemTemplate="{DynamicResource {x:Static local:EditorKeys.NamedColorEditorKey}}"
      SelectedValuePath="Name"
      IsEditable="{Binding IsEditable}"
      IsEnabled="{Binding IsEditable}"/>
  </DataTemplate>


  <DataTemplate x:Key="{x:Static local:EditorKeys.SliderEditorKey}">
    <Slider x:Name="PART_editor"
            Value="{Binding Value}"
            Minimum="{Binding ParentProperty.Metadata[NumberRange].Minimum, FallbackValue=0}"
            Maximum="{Binding ParentProperty.Metadata[NumberRange].Maximum, FallbackValue=100}"
            TickFrequency="{Binding ParentProperty.Metadata[NumberRange].Tick, FallbackValue=1}"
            AutoToolTipPrecision="{Binding ParentProperty.Metadata[NumberRange].Precision, FallbackValue=0}"
            AutoToolTipPlacement="BottomRight"
            IsDirectionReversed="False"
            IsMoveToPointEnabled="True"
            IsSnapToTickEnabled="False"
            IsEnabled="{Binding IsEditable}"
            />
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.PasswordEditorKey}">
    <PasswordBox
      x:Name="PART_editor"
      local:PasswordBoxExtender.BindPassword="true"
      local:PasswordBoxExtender.BoundPassword="{Binding StringValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
      IsEnabled="{Binding IsEditable}"
      />
  </DataTemplate>

  <DataTemplate x:Key="{x:Static local:EditorKeys.DoubleEditorKey}">
    <controls:DoubleEditor
        x:Name="PART_editor"
        Value="{Binding Value, Mode=TwoWay}"
        Minimum="{Binding ParentProperty.Metadata[NumberRange].Minimum}"
        Maximum="{Binding ParentProperty.Metadata[NumberRange].Maximum}"
        DefaultChange="{Binding ParentProperty.Metadata[NumberRange].Tick}"
        MaxPrecision="{Binding ParentProperty.Metadata[NumberRange].Precision}"
        IsEnabled="{Binding IsEditable}"
        />
  </DataTemplate>

</ResourceDictionary>